<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('request_logs')) return;
        Schema::create('request_logs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('host')->default('')->comment('请求域名');
            $table->string('uri')->default('')->comment('请求地址');
            $table->string('param', 2550)->default('')->comment('请求参数，json');
            $table->string('key')->default('')->comment('请求key');
            $table->integer('code')->default(0)->comment('响应code');
            $table->string('message')->default('')->comment('详情信息');
            $table->string('data', 2550)->default('')->comment('响应body');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
            $table->index('created_at');
            $table->index('key');
        });
        DB::statement("ALTER TABLE `request_logs` COMMENT '请求第三方错误日志'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('request_logs');
    }
};
